package liyuxian.fragment.adapter;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.jxnu.duewang.zmly.R;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import liyuxian.fragment.bean.TopRadios;

/**
 * Created by Administrator on 2016/12/7.
 */
public class BradCastAdapter extends RecyclerView.Adapter<BradCastAdapter.ViewHolder>{
    private Context context;
    private List<TopRadios> list;
    public BradCastAdapter(Context context) {
        this.context = context;
        list = new ArrayList<>();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.bradcast,parent,false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        if(position<=2){
            holder.name.setText(list.get(position).getName());
           int count = Integer.parseInt(list.get(position).getPlayCount());
            holder.playCount.setText(count/10000.0+"万");
            holder.programName.setText(list.get(position).getProgramName());
            loadImage(holder.image,list.get(position).getCoverSmall());
            holder.title_text.setVisibility(View.VISIBLE);
            holder.vido.setVisibility(View.VISIBLE);
        }else {
            holder.name.setVisibility(View.GONE);
            holder.programName.setVisibility(View.GONE);
            holder.playCount.setVisibility(View.GONE);
            holder.image.setVisibility(View.GONE);
            holder.title_text.setVisibility(View.GONE);
            holder.vido.setVisibility(View.GONE);
        }


    }
    private void loadImage(ImageView image, String coverSmall) {
        Picasso.with(image.getContext())
                .load(coverSmall)
                .into(image);
    }
    @Override
    public int getItemCount() {
        return list.size();
    }

    public void addAll(Collection<? extends TopRadios> top) {
        int size = list.size();
        list.addAll(top);
        notifyItemRangeInserted(size, top.size());

    }

    public static class ViewHolder extends RecyclerView.ViewHolder {

        private ImageView image;
        private TextView name;
        private TextView programName;
        private TextView playCount;
        private ImageView vido ;
        private TextView title_text ;
        public ViewHolder(View itemView) {
            super(itemView);
            image = (ImageView) itemView.findViewById(R.id.brad_image);
            name = (TextView) itemView.findViewById(R.id.name);
            programName = (TextView) itemView.findViewById(R.id.programName);
            playCount = (TextView) itemView.findViewById(R.id.playCount);
            vido = (ImageView) itemView.findViewById(R.id.vdio);
            title_text = (TextView) itemView.findViewById(R.id.title_text);
        }
    }

}
